using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;

namespace OptimusPluginLib
{
  public partial class PluginOptionsForm : Form
  {
    [Obsolete]
    public PluginOptionsForm()
    {
      InitializeComponent();
    }

    public PluginOptionsForm(Image ActiveIcon, Image InactiveIcon,
                             string PathToWinamp, string DirectoryToPlay)
    {
      InitializeComponent();

      imgActiveIcon.Image = ActiveIcon;
      imgInactiveIcon.Image = InactiveIcon;

      txtPathToWinamp.Text = PathToWinamp;
      txtDirectoryToPlay.Text = DirectoryToPlay;
    }

    #region Properties

    public Image ActiveIcon
    {
      get { return imgActiveIcon.Image; }
    }

    public Image InactiveIcon
    {
      get { return imgInactiveIcon.Image; }
    }

    public string PathToWinamp
    {
      get { return txtPathToWinamp.Text; }
    }

    public string DirectoryToPlay
    {
      get { return txtDirectoryToPlay.Text; }
    }

    #endregion

    private void btnOpenWinampPath_Click(object sender, EventArgs e)
    {
      dlgOpenWinampPath.FileName = txtPathToWinamp.Text;

      if (dlgOpenWinampPath.ShowDialog() == DialogResult.OK)
      {
        txtPathToWinamp.Text = dlgOpenWinampPath.FileName;
      }
    }

    private void btnOpenDirectoryToPlay_Click(object sender, EventArgs e)
    {
      dlgOpenDirectoryToPlay.SelectedPath = txtDirectoryToPlay.Text;

      if (dlgOpenDirectoryToPlay.ShowDialog() == DialogResult.OK)
      {
        txtDirectoryToPlay.Text = dlgOpenDirectoryToPlay.SelectedPath;
      }
    }

    #region Helpers

    private void LoadIcon(PictureBox IconBox)
    {
      // new Bitmap(Image, 96, 96)
      if (dlgOpenIcon.ShowDialog() == DialogResult.OK)
      {
        Image image = Image.FromFile(dlgOpenIcon.FileName);
        
        if (image.RawFormat.Equals(ImageFormat.Gif) &&
          image.Width != 96 && image.Height != 96)
        {
          MessageBox.Show("Gif images should have size of 96x96 px",
            "Image incompatibility", 
            MessageBoxButtons.OK, MessageBoxIcon.Error);
          return;
        }

        // scales an image
        IconBox.Image = (image.RawFormat.Equals(ImageFormat.Gif)) ? image : new Bitmap(image, 96, 96);
      }
    }

    #endregion

    #region Event handlers

    private void btnLoadIcon_Click(object sender, EventArgs e)
    {
      LoadIcon(imgActiveIcon);
    }

    private void btnLoadInactiveIcon_Click(object sender, EventArgs e)
    {
      LoadIcon(imgInactiveIcon);
    }

    #endregion

  }
}